/**  
 * All rights Reserved, Designed By www.woniuxy.com
 * @Title:  Account.java   
 * @Package com.woniu.domain   
 * @Description:    Description  
 * @author: 蜗牛学院  
 * @date:   2019年8月29日 下午8:41:27
 * @user:   Administrator  
 * @version V1.0 
 * @Copyright: 2019 www.woniuxy.com Inc. All rights reserved. 
 * 注意：本内容仅限于成都蜗牛创想科技有限公司，禁止外泄以及用于其他的商业目
 */ 
package com.woniu.ssm.controller;

import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.woniu.ssm.domain.User;
import com.woniu.ssm.service.BookService;
import com.woniu.ssm.service.UserService;
import com.woniu.ssm.util.PageBean;
import com.woniu.ssm.vo.Bookvo;
import com.woniu.ssm.vo.Queryvo;

/**
 * @author Administrator
 *
 */
@Controller
@RequestMapping("user")
public class UserContorller {
	@Autowired
	UserService us;
	@Autowired
	BookService bs;
	@RequestMapping("login")
	public String login(String uname,String upass,HttpServletRequest req,Map map) {
		User user = us.login(uname);		
		if(user==null) {
			map.put("error", "用户名不存在");
		}else if(upass.equals(user.getUpass())) {
			req.getSession().setAttribute("user", user);
			return "redirect:lists";
		}else {
			map.put("error", "密码错误");
		}
		
		return null;
	}
	
	@RequestMapping("lists")
	public String list(Queryvo query,Map map) {
		PageBean pb = bs.findList(query);
		map.put("pb", pb);
		map.put("query", query);
		return "list";
	}
	@RequestMapping("borrow")
	@ResponseBody
	public String borrow(int bid,HttpServletRequest req) {
		User user = (User) req.getSession().getAttribute("user");
		bs.borrow(user.getUid(),bid);
		return "1";
	}
	@RequestMapping("borrowlist")
	public String borrowList(Map map,HttpServletRequest req) {
		User user = (User) req.getSession().getAttribute("user");
		List<Bookvo> lists = bs.findMyBook(user.getUid());
		map.put("myBook", lists);
		return "borrowlist";
	}
	@RequestMapping("delbook")
	public String delBook(int bid) {
		bs.delBook(bid);
		return "redirect:borrowlist";
	}
}
